﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using YouHP.Model;
using YouHP.Utility;
using YouHP.BLL;

namespace web.admin
{
    public partial class DistrictAdd : System.Web.UI.Page
    {
        protected int parentId =7;
        protected string Url_Back;
        protected string flag;
        protected string flag1;
        protected void Page_Load(object sender, EventArgs e)
        {
           parentId = RequestTools.GetQueryInt("parentId", -1);
           if (parentId == 0)
           {
               Url_Back = "ProvinceList.aspx";
               flag = "省份列表";
               flag1 = "添加省份";
           }
           else
           {
               Url_Back = "CityList.aspx?parentId=" + parentId;
               flag = "城市列表";
               flag1 = "添加城市";
           }

        }
        protected void InsertButton_click(object sender, EventArgs e)
        {
           
            //数据有效性检查
            try
            {
                DistrictInfo info = validateForm(this.districtInfo);

                if (info != null)
                {
                    //准备数据,调用SqlServerDAL执行增加
                    if (DistrictBLL.Instance.AddDistrict(info))  //成功
                    {
                        HttpContext.Current.Response.Redirect(Url_Back, true);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void CancelButton_click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect(Url_Back, true);
        }

        private DistrictInfo validateForm(DetailsView detailsView)
        {
            DistrictInfo info = new DistrictInfo();
            info.Name = ((TextBox)detailsView.FindControl("name")).Text;
            info.OrderValue = Convert.ToInt32(((TextBox)detailsView.FindControl("ordervalue")).Text);
            info.ParentId = parentId;
            return info;
        }


    }
}
